/*
Copyright (C) Ariff Ehsan, Abdul Hadi Fikri

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*  Author : Ariff Ehsan
 *  Date   : June 28, 2009
 */


#include <system.h>
#include <button/button.h>
#include <leds8/leds8.h>


button_t app_button0;
void APP_BUTTON0_event(uint8_t);

button_t app_button1;
void APP_BUTTON1_event(uint8_t);

task_t app_task;
void APP_TASK_run(void);


void APP_booted(){
	
	/* initialize leds */
	LEDS8_init();
	
	/* set pin PB0 and PB1 as input */
	CLR_BIT(DDRB, PB0);
	CLR_BIT(DDRB, PB1);
	
	/* initialize button module */
	BUTTON_init();
	
	/* register and start button */
	BUTTON_reg(&app_button0, (uint8_t*)(&PINB), PB0, APP_BUTTON0_event);
	BUTTON_reg(&app_button1, (uint8_t*)(&PINB), PB1, APP_BUTTON1_event);
	BUTTON_start(&app_button0);
	BUTTON_start(&app_button1);
}


void APP_BUTTON0_event(uint8_t state) {
	if (state == BUTTON_PUSHED) {
		LEDS8_toggle(PC0);
	}
}


void APP_BUTTON1_event(uint8_t state) {
	if (state == BUTTON_PUSHED) {
		LEDS8_toggle(PC1);
	}
}
